<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>详情页</title>
</head>

<body>
    <div id="detail"></div>
    <script src="ajax.js"></script>
    <script>
        const baseUrl = "http://localhost:8888";
        let id = location.search.split("=")[1];
        let detail = document.getElementById("detail");
        ajax({
            url: baseUrl + "/goods/item",
            type: "get",
            params: { id },
            fn(resData) {
                //console.log(JSON.parse(resData));
                resData = JSON.parse(resData);
                detail.innerHTML = `
          <img src="${resData.info.img_big_logo}">
          <p>${resData.info.title}</p>
          <input type="button" value="加入购物车">
          ${resData.info.goods_introduce}
          `;

                let oInput = document.querySelector("input");
                oInput.onclick = function () {
                    ajax({
                        url: baseUrl + "/cart/add",
                        type: "post",
                        params: { id: localStorage.getItem("uid"), goodsId: id },
                        author: true,
                        fn(resData) {
                            location.href = "05car.html";
                        },
                    });
                };
            },
        });
    </script>
</body>

</html>